package com.binguo.wxapi.transfer;

import org.springframework.stereotype.Service;

import java.util.concurrent.atomic.AtomicInteger;

@Service
public class OrderNoBuilder {
	private final int MIN_INDEX = 100000;
	private final int MAX_INDEX = Integer.MAX_VALUE - MIN_INDEX;

	private AtomicInteger index = new AtomicInteger(MIN_INDEX);

	public String createPlatformOrderNo() {
		//时间戳
		long now = System.currentTimeMillis();
		//自增序列号
		int i = index.getAndIncrement();
		
		if(i > MAX_INDEX)
			index.set(MIN_INDEX);
		
		//格式化订单号（时间戳+自增序号）
		StringBuilder sb = new StringBuilder();
		sb.append(now).append(i);
		return sb.toString();
	}
}
